// 构造函数类
function LazyMan (name) {
	this.name = name;
	console.log('Hi I am '+name);
	this.fn=[];
	this.next = function () {
		let fnc = this.fn.shift();
		fnc && fnc();
	};
	setTimeout(() => {
		this.next();
	},0)
}
LazyMan.prototype.sleep = function (time) {
	let func = (function (time,that) {
			return function () {
				setTimeout(()=>{
					console.log('等待了...'+time+'s');
					that.next();
				}, time*1000);
			}
		})(time,this);
	this.fn.push(func);
	return this;
	// .then(res=>{
	// 	return Promise.resolve()
	// });
}
LazyMan.prototype.sleepFirst = function (time) {
	let func = (function (time,that) {
			return function () {
				setTimeout(()=>{
					console.log('等待了...'+time+'s');
					that.next();
				}, time*1000);
			}
		})(time,this);
	this.fn.unshift(func);
	return this;
}
LazyMan.prototype.eat = function (food) {
	let func = (function (food,that) {
			return function () {
				console.log('I am eating ' + food);
				that.next();
			}
		})(food,this);
	this.fn.push(func);
	// console.log(this.fn);
	return this;
}
new LazyMan('Tony').eat('lunch').eat('dinner').sleepFirst(5).sleep(5).eat('junk food');